﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using Common;

namespace Validation
{
    public class Customer : BaseClass, IDataErrorInfo
    {
        private string name;
        public string Name
        {
            get { return name; } 
            set 
            { 
                name = value;
                OnPropertyChanged("Name");
            }
        }

        private int age;
        public int Age
        {
            get { return age; }
            set
            {
                age = value;
                OnPropertyChanged("Age");
            }
        }

        string IDataErrorInfo.Error
        {
            get { return null; }
        }

        string IDataErrorInfo.this[string columnName]
        {
            get
            {
                switch (columnName)
                {
                    case "Name":
                        if (!String.IsNullOrEmpty(name) && name.Contains("ab"))
                            return "Name error";
                        break;
                    case "Age":
                        if (age > 100)
                            return "Age error";
                        break;
                    default:
                        return null;
                }
                return null;
            }
        }
    }
}
